//
//  Boundary.m
//  ProjectL
//
//  Created by Nguyen Tan Loc on 8/18/13.
//  Copyright (c) 2013 Nguyen Tan Loc. All rights reserved.
//

#import "Boundary.h"

@implementation Boundary

-(id) init
{
    if (self = [super init])
    {
        [self createBody];
    }
    
    return self;
}

-(void) createBody
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    b2BodyDef bodyDef;
	bodyDef.position.Set(0, 0); // bottom-left corner
	
    _b2Body = PhysicSystem::getInstance()->mWorld->CreateBody(&bodyDef);

	b2EdgeShape shape;
	
    
	shape.Set(b2Vec2(0, 0), b2Vec2(winSize.width / PTM_RATIO, 0));
    [self createFixtureWithShape:shape];
    
    // top
    shape.Set(b2Vec2(0, winSize.height / PTM_RATIO), b2Vec2(winSize.width / PTM_RATIO, winSize.height / PTM_RATIO));
	[self createFixtureWithShape:shape];
    
    // left
    shape.Set(b2Vec2(0, 0), b2Vec2(0, winSize.height / PTM_RATIO));
	[self createFixtureWithShape:shape];
    
    // right
    shape.Set(b2Vec2(winSize.width / PTM_RATIO, winSize.height / PTM_RATIO), b2Vec2(winSize.width / PTM_RATIO, 0));
	[self createFixtureWithShape:shape];
}

-(void) createFixtureWithShape:(b2EdgeShape)shape
{
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &shape;
    fixtureDef.filter.categoryBits = [self getObjectType];
    fixtureDef.filter.maskBits = MASK_BIT_BOUNDARY;
    fixtureDef.isSensor = true;
    _b2Body->CreateFixture(&fixtureDef);
}

-(OBJECT_TYPE) getObjectType
{
    return eO_BOUNDARY;
}

-(NSString *) getSpriteFrameName
{
    return SFN_BOMB;
}

@end
